package com.tzy.spi.aop.Interceptor;

import com.tzy.spi.aop.JoinPoint;


import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

public class AroundMethodInterceptor extends AbstractMethodInterceptor {



    public Object toDo(JoinPoint joinPoint)  {

        Method method = getMethod();

        try{
            if(method.getParameterCount()==0){
                return method.invoke(getAspect());

            }else {
                Parameter parameter = method.getParameters()[0];

                if(parameter.getType().getName().equals(JoinPoint.class.getName())){
                    return method.invoke(getAspect(),joinPoint);
                }else {
                    throw new RuntimeException("参数不匹配 !!!");
                }
            }
        }catch (Exception e){
            throw new RuntimeException(e.getMessage());
        }

    }
}
